package com.gewu.pm.ui.activity.sales;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.viewpager.widget.ViewPager;

import com.androidkun.xtablayout.XTabLayout;
import com.gewu.pm.R;
import com.gewu.pm.app.AppActivity;
import com.gewu.pm.app.AppFragment;
import com.gewu.pm.other.IntentKey;
import com.gewu.pm.ui.fragment.sales.SalesLeadDetailFragment;
import com.gewu.pm.ui.fragment.sales.SalesLeadVisitRecordFragment;
import com.hjq.base.FragmentPagerAdapter;

/**
 * 销售线索详情页面
 * 
 * 功能：
 * 1. 展示线索基本信息
 * 2. Tab 切换：详情 / 拜访记录
 * 3. 详情页展示线索完整信息
 * 4. 拜访记录页展示拜访历史
 */
public final class SalesLeadDetailActivity extends AppActivity {

    // 线索信息卡片
    private ImageView mLeadPhotoView;
    private TextView mLeadNameView;
    private TextView mLeadCodeView;
    private TextView mLeadAddressView;

    // Tab + ViewPager
    private XTabLayout mTabLayout;
    private ViewPager mViewPager;
    private FragmentPagerAdapter<AppFragment<?>> mPagerAdapter;

    public static void start(Context context, String leadName) {
        Intent intent = new Intent(context, SalesLeadDetailActivity.class);
        intent.putExtra(IntentKey.TITLE, leadName);
        context.startActivity(intent);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.sales_lead_detail_activity;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        // 线索信息卡片
        mLeadPhotoView = findViewById(R.id.iv_lead_photo);
        mLeadNameView = findViewById(R.id.tv_lead_name);
        mLeadCodeView = findViewById(R.id.tv_lead_code);
        mLeadAddressView = findViewById(R.id.tv_lead_address);

        // Tab + ViewPager
        mTabLayout = findViewById(R.id.tab_layout);
        mViewPager = findViewById(R.id.view_pager);

        // 初始化 FragmentPagerAdapter
        mPagerAdapter = new FragmentPagerAdapter<>(this);
        mPagerAdapter.addFragment(SalesLeadDetailFragment.newInstance(), "详情");
        mPagerAdapter.addFragment(SalesLeadVisitRecordFragment.newInstance(), "拜访记录");
        mViewPager.setAdapter(mPagerAdapter);

        // 关联 XTabLayout 和 ViewPager
        mTabLayout.setupWithViewPager(mViewPager);

        setOnClickListener(mLeadNameView);
    }

    @Override
    protected void initData() {
        String leadName = getString(IntentKey.TITLE);
        // 显示线索信息
        mLeadNameView.setText(leadName);
        // TODO: 加载完整详情数据
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        if (view == mLeadNameView){//编辑
            SalesLeadAddTwoActivity.start(getContext(),"呦呦呦","123","杭州","中医药大学","");
        }
    }
}

